﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Back.Xinkui.Entity.Manager;
using DataFrameworkAccess;

namespace Back.Xinkui.DataAccess.Manager
{
    public class ManagerUserDataAccess
    {
        public static VManagerUserEntity GetUserByUserName(string UserName, string Password)
        {
            DataCommand command = DataCommandManager.GetDataCommand("Query.ManagerUser.GetUserByUserNamePassword");
            command.SetParameterValue("@UserName", UserName);
            command.SetParameterValue("@Password", Password);
            return command.ExecuteEntity<VManagerUserEntity>();
        }
        public static VManagerUserEntity GetUserByUserID(int UserID)
        {
            DataCommand command = DataCommandManager.GetDataCommand("Query.ManagerUser.GetUserByUserID");
            command.SetParameterValue("@UserID", UserID);
            return command.ExecuteEntity<VManagerUserEntity>();
        }


        public static List<VManagerUserEntity> GetManageUserList(int AppID, string keyword, int Ishave, int StartRowID, int EndRowID, out int RecordCount)
        {
            keyword = string.IsNullOrEmpty(keyword) ? "" : "%" + keyword + "%";
            DataCommand command = DataCommandManager.GetDataCommand("Query.Pages.GetManageUserList");
            command.SetParameterValue("@Ishave", Ishave);
            command.SetParameterValue("@AppID", AppID);
            command.SetParameterValue("@keyword", keyword);
            command.SetParameterValue("@StartRowID", StartRowID);
            command.SetParameterValue("@EndRowID", EndRowID);
            var list = command.ExecuteEntityList<VManagerUserEntity>();
            RecordCount = (int)command.GetParameterValue("@RecordCount");
            return list;
        }
        /// <summary>
        /// 检查用户名是否存在
        /// </summary>
        /// <param name="UserName"></param>
        /// <returns></returns>
        public static bool ExistsUser(string UserName)
        {
            DataCommand command = DataCommandManager.GetDataCommand("Query.ManagerUser.ExistsUser");
            command.SetParameterValue("@UserName", UserName);
            return command.ExecuteScalar<int>() == 1 ? true : false;
        }
    }
}
